package com.twl.app.base.bo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.twl.app.base.entity.Bfsalary;
import com.twl.app.base.entity.Jsbfmoney;
import com.twl.app.base.entity.Leavebmoney;
import com.twl.app.base.entity.Loyalward;
import com.twl.app.base.entity.Moneyadjust;
import com.twl.app.base.entity.Overtimemeals;
import com.twl.app.base.entity.Overtimemoney;
import com.twl.app.base.entity.Shiftallowance;
import com.twl.app.base.entity.Uemp;
import com.twl.app.base.util.CryptUtils;
import com.twl.app.base.util.NotNullBeanUtils;
import com.twl.core.framework.bo.impl.AbsCrudBoImpl;
import com.twl.core.framework.dao.WSHibernateDaoSupportProxy;

@Transactional
@Repository("adjuestBo")
public class AdjuestBoImpl extends AbsCrudBoImpl{

	@Autowired
	private WSHibernateDaoSupportProxy wSHibernateDaoSupportProxy;
	
	public String  insertMoneyadjust(Moneyadjust moneyadjust){
		try {
			String hql = "from Moneyadjust where staffint='"+moneyadjust.getStaffint()+"' and Datemoney='"+moneyadjust.getDatemoney()+"'";
			List<Moneyadjust> listMA = super.findAll(hql);
			//解密
			List<Moneyadjust> list = CryptUtils.decrypt(listMA);

			if(list.size()>0){
				//moneyadjust.setDid(list.get(0).getDid());
				NotNullBeanUtils.copyProperties(list.get(0),moneyadjust);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(moneyadjust);

			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;

		}
		return "ok";
	}
	
	
	public String insertLeavebmoney(Leavebmoney leavebmoney){
		try {
			String hql = "from Leavebmoney where staffint='"+leavebmoney.getStaffint()+"' and Datemoney='"+leavebmoney.getDatemoney()+"'";
			List<Leavebmoney> listLB = super.findAll(hql);
			//解密
			List<Leavebmoney> list = CryptUtils.decrypt(listLB);
			if(list.size()>0){
				leavebmoney.setDid(list.get(0).getDid());
				NotNullBeanUtils.copyProperties(list.get(0),leavebmoney);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));
			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(leavebmoney);
			}

		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;

		}
		
		return "ok" ;
	}
	
	public String insertOvertimemoney(Overtimemoney overtimemoney){
		
		try {
			String hql = "from Overtimemoney where staffint='"+overtimemoney.getStaffint()+"' and Datemoney='"+overtimemoney.getDatemoney()+"'";
			List<Overtimemoney> listOT = super.findAll(hql);
			//解密
			List<Overtimemoney> list = CryptUtils.decrypt(listOT);
			if(list.size()>0){
				NotNullBeanUtils.copyProperties(list.get(0),overtimemoney);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(overtimemoney);

			}

		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;

		}
		return "ok";
	}
	
	public String insertOvertimemeals(Overtimemeals overtimemeals){
		try {
			String hql = "from Overtimemeals where staffint='"+overtimemeals.getStaffint()+"' and Datemoney='"+overtimemeals.getDatemoney()+"'";
			List<Overtimemeals> listOT = super.findAll(hql);
			//解密
			List<Overtimemeals> list = CryptUtils.decrypt(listOT);
			if(list.size()>0){
				NotNullBeanUtils.copyProperties(list.get(0),overtimemeals);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(overtimemeals);

			}

		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;

		}
		return "ok";
	}
	
	public String insertShiftallowance(Shiftallowance shiftallowance){
		try {
			String hql = "from Shiftallowance where staffint='"+shiftallowance.getStaffint()+"' and Datemoney='"+shiftallowance.getDatemoney()+"'";
			List<Shiftallowance> listSA = super.findAll(hql);
			//解密
			List<Shiftallowance> list = CryptUtils.decrypt(listSA);
			if(list.size()>0){
				NotNullBeanUtils.copyProperties(list.get(0),shiftallowance);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(shiftallowance);

			}

		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;

		}
		
		return "ok";
	}
	
	public String insertLoyalward(Loyalward loyalward){
		try {
			String hql = "from Loyalward where staffint='"+loyalward.getStaffint()+"' and Datemoney='"+loyalward.getDatemoney()+"'";
			List<Loyalward> listLW = super.findAll(hql);
			//解密
			List<Loyalward> list=  CryptUtils.decrypt(listLW);
			if(list.size()>0){
				NotNullBeanUtils.copyProperties(list.get(0),loyalward);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(loyalward);

			}

		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;

		}
		return "ok";
	}
	
	public String updateBf(Uemp uemp){
		try {
			super.updateData(uemp);
		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;
		}
		return "ok" ;
	}
}
